﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.Dim
{
    /// <summary>
    /// 获取维度信息
    /// </summary>
    [CPPEI.WebApi.AuthGetAction("Dim", "GetItem", "1.0")]
    public class GetItemAction : BaseAction<GetItemParams, GetItemResult>
    {
        protected override ActionResult<GetItemResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            GetItemParams opParams)
        {
            SER.DimService service = new SER.DimService();
            ServiceResult<ENT.EDimItem> serResult = service.GetDimItem(opParams.DimItemId);
            if(serResult.IsSuccess)
            {
                GetItemResult result = new GetItemResult();
                result.Id = serResult.Data.Id;
                result.Code = serResult.Data.Code;
                result.Name = serResult.Data.Name;
                result.CreatedTime = serResult.Data.CreatedTime;
                result.Creator = serResult.Data.Creator;
                result.DimId = serResult.Data.DimId;
                result.EffectiveDate = serResult.Data.EffectiveDate;
                result.ExpiryDate = serResult.Data.ExpiryDate;
                return new ActionResult<GetItemResult>(result);
            }
            else
            {
                return new ActionResult<GetItemResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class GetItemParams
    {
        public Guid DimItemId { get; set; }
    }

    public class GetItemResult
    {
        public Guid Id { get; set; }

        public Guid DimId { get; set; }

        public string Code { get; set; }

        public string Name { get; set; }

        public string Creator { get; set; }

        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 生效日期
        /// </summary>
        public DateTime EffectiveDate { get; set; }

        /// <summary>
        /// 失效日期
        /// </summary>
        public DateTime ExpiryDate { get; set; }
    }
}
